<admintpl file="header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="javascript:;">用户选择列表</a></li>
    </ul>
    <form class="well form-search" method="post" action="{:U('Ticketadmin/memberList')}">
        用户账号：
        <input type="text" name="username" style="width: 200px;" value="{$formget.username}" placeholder="请输入用户名">
        用户昵称：
        <input type="text" name="nickname" style="width: 200px;" value="{$formget.nickname}" placeholder="请输入用户昵称">
        注册时间：
        <input type="text" class="js-date" name="start_time" style="width: 120px;" value="{$formget.start_time}" placeholder="">&nbsp;
        至:&nbsp;
        <input type="text" class="js-date" name="end_time" style="width: 120px;" value="{$formget.end_time}" placeholder="">
        <input type="submit" class="btn btn-primary" value="搜索"/>
        <input type="hidden" name="ticket_id" value="{$ticket_id}">
    </form>
    <input type="text" class="hidden" id="ticket_id" style="width: 120px; display: none;" value="{$ticket_id}" placeholder="">

    <button class="btn btn-primary js-ajax-submit" id="send_ticket" type="">确认发送</button>
    <a class="btn" href="{:U('Ticketadmin/lists')}">返回</a>

    <table style="margin-top: 10px;word-break:break-all;" class="table table-hover table-bordered table-list"
           id="menus-table">
        <thead>
        <tr>
            <th>
                <input type="checkbox" name="checkAll" id="checkAll" value=""/>全选
            </th>
            <th>序号</th>
            <th>用户名</th>
            <th>昵称</th>
            <!--<th>备注</th>-->
            <th>注册时间</th>
            <!--<th>操作</th>-->
        </tr>
        </thead>
        <tbody>
        {$categorys}
        </tbody>
    </table>
    <div class="pagination">{$Page}</div>
</div>

    <script src="__PUBLIC__/js/common.js"></script>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">×
                </button>
                <h4 class="modal-title" id="myModalLabel">

                </h4>
            </div>
            <div class="modal-body">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default"
                        data-dismiss="modal">关闭
                </button>
                <button type="button" id="alert_content" class="btn btn-primary">
                    提交更改
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<script>
        $(function(){
            function initTableCheckbox() {
                var $thr = $('table thead tr');
                var $checkAllTh = $('<th><input type="checkbox" id="checkAll" name="checkAll" /></th>');
                /*将全选/反选复选框添加到表头最前，即增加一列*/
//                $thr.prepend($checkAllTh);
                /*“全选/反选”复选框*/
                var $checkAll = $thr.find('input');
                $checkAll.click(function(event){
                    /*将所有行的选中状态设成全选框的选中状态*/
                    $tbr.find('input').prop('checked',$(this).prop('checked'));
                    /*并调整所有选中行的CSS样式*/
                    if ($(this).prop('checked')) {
                        $tbr.find('input').parent().parent().addClass('warning');
                    } else{
                        $tbr.find('input').parent().parent().removeClass('warning');
                    }
                    /*阻止向上冒泡，以防再次触发点击操作*/
                    event.stopPropagation();
                });
                /*点击全选框所在单元格时也触发全选框的点击操作*/
                $checkAllTh.click(function(){
                    $(this).find('input').click();
                });
                var $tbr = $('table tbody tr');
                var $checkItemTd = $('<td><input type="checkbox" name="checkItem" /></td>');
                /*每一行都在最前面插入一个选中复选框的单元格*/
//                $tbr.prepend($checkItemTd);
                /*点击每一行的选中复选框时*/
                $tbr.find('input').click(function(event){
                    /*调整选中行的CSS样式*/
                    $(this).parent().parent().toggleClass('warning');
                    /*如果已经被选中行的行数等于表格的数据行数，将全选框设为选中状态，否则设为未选中状态*/
                    $checkAll.prop('checked',$tbr.find('input:checked').length == $tbr.length ? true : false);
                    /*阻止向上冒泡，以防再次触发点击操作*/
                    event.stopPropagation();
                });
                /*点击每一行时也触发该行的选中操作*/
                $tbr.click(function(){
                    $(this).find('input').click();
                });
            }
            initTableCheckbox();
        });
        
        $('#send_ticket').click(function () {
            var checked = $("input[type=checkbox][name=checkItem]:checked");
            var mid = '';
            checked.each(function () {
                mid = mid ? (mid + ','+$(this).val()) : $(this).val();
            });
            if(mid == '') {
                alert('请选择发送对象');return;
            }
            var ticket_id = $('#ticket_id').val();console.log(ticket_id);
            if(confirm('确定发送吗')) {
                $.ajax({

                    url: "{:U('Consumer/Ticketadmin/sendTicket')}",
                    dataType:"json",
                    data:{mid: mid, ticket_id: ticket_id},
                    type:'POST',
                    async:true,
                    beforeSend:function(){

//                $("body").showLoading();
                    },//下面就是获取到的下载地址，直接通过document.location函数获取下载
                    success:function(rst){
                        if(rst.ret == '200') {
                            alert('成功');
//                        $('#alert_content').html('成功');
//                        $(function () { $('#myModal').modal({
//                            keyboard: true
//                        })});
                            setTimeout(function(){
                                window.location.href = ("{:U('Consumer/Ticketadmin/lists')}");
                            }, 1000);

                        } else if(rst.ret == '210') {
                            alert(rst.msg);
                        }

                    },
                    error: function(){
//                $("body").hideLoading();
//                    alert("错误");
                    }

                });
            }

        })
    </script>


    <script src="__PUBLIC__/js/common.js"></script>
</body>
</html>